<?php

/*

Process adoption (getpet.pro.php)

*/
ob_start();
$rank_check = 1;
include "global.inc.php";

$findGetFirsts = fetch("SELECT * FROM pets2 WHERE game = '$game' AND id = '$species'");

if (!$findGetFirsts[id])
{
	die(header(error("getpet.php?game=$game","Select a real pet.")));
}

if ($findGetFirsts[starter] == 0)
{
	die(header(error("getpet.php?game=$game","Select a starter pet.")));
}

$num_pets = mysql_num_rows(mysql_query("SELECT * FROM user_pets2 WHERE owner = '$userid' AND game = '$game'"));

if ($num_pets != 0)
{
	die(header(error("index.php?game=$game","You already have a pet.")));
}

$check = fetch("SELECT * FROM user_pets2 WHERE name = '$petname' AND game = '$game'");
if ($check[name])
{
	die(header(error("getpet.php?game=$game&pet=$species","There is already a pet with that name. Try another name.")));
}
if ($petname == "")
{
	die(header(error("getpet.php?game=$game&pet=$species","Don't leave the name blank.")));
}

if (preg_match('/^[a-zA-Z0-9_]*$/UD',$petname))
{
	mysql_query("INSERT INTO user_pets2 (name,species,owner,level,strength,intelligence,speed,hunger,timestamp,defense,current_hp,max_hp,game) VALUES ('$petname','$species','$userid','1','7','7','7','7','$timestamp','7','100','100','$game')");
}
else
{
	die(header("Location: $base_url/getpet.php?game=$game&error=" . space2plus("Your pet's name can only contain a-z, A-Z, 0-9 and underscores. Please try again.")));
}

die(header(error("mypets.php?game=$game","Congratulations, your new pet is named $petname.")));

?>